What is strip-eof?
The strip-eof npm package is a utility that removes the end-of-file (EOF) newline character from a string or buffer. This can be useful in various scenarios where you need to ensure that the string or buffer does not end with a newline character.
What are strip-eof's main functionalities?
Remove EOF newline from a string
This feature allows you to remove the EOF newline character from a string. In the example, the input string 'Hello, world!\n' is processed by strip-eof to produce 'Hello, world!' without the trailing newline.
const stripEof = require('strip-eof');
const input = 'Hello, world!\n';
const output = stripEof(input);
console.log(output); // 'Hello, world!'
Remove EOF newline from a buffer
This feature allows you to remove the EOF newline character from a buffer. In the example, the input buffer containing 'Hello, world!\n' is processed by strip-eof to produce a buffer containing 'Hello, world!' without the trailing newline.
const stripEof = require('strip-eof');
const input = Buffer.from('Hello, world!\n');
const output = stripEof(input);
console.log(output.toString()); // 'Hello, world!'
Other packages similar to strip-eof
trim-newlines
The trim-newlines package is used to trim newlines from the start and/or end of a string. Unlike strip-eof, which only removes the EOF newline, trim-newlines can remove newlines from both ends of the string, providing more flexibility in handling newline characters.
newline-remove
The newline-remove package removes all newline characters from a string, not just the EOF newline. This can be useful if you need to ensure that a string contains no newline characters at all, whereas strip-eof focuses solely on the EOF newline.
strip-eof
Strip the End-Of-File (EOF) character from a string/buffer
Install
$ npm install --save strip-eof
Usage
const stripEof = require('strip-eof');
stripEof('foo\nbar\n\n');
stripEof(new Buffer('foo\nbar\n\n')).toString();
License
MIT © Sindre Sorhus